package com.ticket.web.controller.yanchu;

import com.ticket.common.annotation.Log;
import com.ticket.common.core.controller.BaseController;
import com.ticket.common.core.domain.AjaxResult;
import com.ticket.common.core.domain.model.LoginUser;
import com.ticket.common.enums.BusinessType;
import com.ticket.common.utils.poi.ExcelUtil;
import com.ticket.framework.web.service.TokenService;
import com.ticket.system.domain.YanchuAttach;
import com.ticket.system.service.IYanchuAttachService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 演出附表Controller
 * 
 * @date 2023-04-03
 */
@RestController
@RequestMapping("/system/attach")
public class YanchuAttachController extends BaseController
{
    @Autowired
    private TokenService tokenService;
    @Autowired
    private IYanchuAttachService yanchuAttachService;

    /**
     * 查询演出附表列表
     */
    @GetMapping("/list")
    public Map list(YanchuAttach yanchuAttach)
    {
        startPage();
        List<YanchuAttach> list = yanchuAttachService.selectYanchuAttachList(yanchuAttach);
        YanchuAttach collect = yanchuAttachService.selectYanchuAttachCollect(yanchuAttach);
        Map map = new HashMap();
        map.put("list",getDataTable(list));
        map.put("collect",collect);
        return map;
    }

    /**
     * 导出演出附表列表
     */
    @Log(title = "演出附表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YanchuAttach yanchuAttach)
    {
        List<YanchuAttach> list = yanchuAttachService.selectYanchuAttachList(yanchuAttach);
        ExcelUtil<YanchuAttach> util = new ExcelUtil<YanchuAttach>(YanchuAttach.class);
        util.exportExcel(response, list, "演出附表数据");
    }

    /**
     * 获取演出附表详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yanchuAttachService.selectYanchuAttachById(id));
    }

    /**
     * 新增演出附表
     */
    @Log(title = "演出附表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YanchuAttach yanchuAttach, HttpServletRequest request)
    {
        LoginUser loginUser = tokenService.getLoginUser(request);
        yanchuAttach.setCreateBy(loginUser.getUserId()+"");
        yanchuAttach.setCreateDate(new Date());
        yanchuAttach.setUpdateDate(new Date());
        return toAjax(yanchuAttachService.insertYanchuAttach(yanchuAttach));
    }

    /**
     * 新增演出附表
     */
    @Log(title = "演出附表", businessType = BusinessType.INSERT)
    @PostMapping("/addBatch")
    public AjaxResult addBatch(@RequestBody List<YanchuAttach> yanchuAttach)
    {
        return toAjax(yanchuAttachService.insertBatchYanchuAttach(yanchuAttach));
    }

    /**
     * 修改演出附表
     */
    @Log(title = "演出附表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YanchuAttach yanchuAttach)
    {
        return toAjax(yanchuAttachService.updateYanchuAttach(yanchuAttach));
    }

    /**
     * 删除演出附表
     */
    @Log(title = "演出附表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yanchuAttachService.deleteYanchuAttachByIds(ids));
    }
}
